package com.usian.wemedia.controller;

import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserService userService;

    /**
     * 保存自媒体用户
     *
     * @param wmUser
     * @return
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        userService.save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 根据名字查询自媒体用户
     *
     * @param name
     * @return
     */
    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable  String name) {
        List<WmUser> wmUsersList = userService.findByName(name);
        if(wmUsersList.size()>0){
            return wmUsersList.get(0);
        }
        return null;
    }
}
